import { Injectable } from '@nestjs/common';
import { DbService } from '../../db/db.service';
import { DistributionConfig } from '@app/db/entity/DistributionConfig';

@Injectable()
export class DistributionService {
    constructor(
        private readonly db:DbService,
    ){}

    async setConfig(dto:DistributionConfig) {
        const rows = await this.db.distributionConfig.find()
        if(rows.length == 0) {
            return this.db.distributionConfig.insert(dto)
        }

        return this.db.distributionConfig.update({id: rows[0].id}, dto)
    }

    async getConfig() {
        const rows = await this.db.distributionConfig.find()
        if(rows.length == 0) {
            return null
        }

        return rows[0]
    }

    
}
